/**
 * ENGLISH LENGTH UNITS
 * Contains INCHES, FEET, YARDS, MILES
 * METRIC BASE: METER
 * Each unit is set up as:
 * 
 * UNITS {
 * 
 * 	-- Returns value in same units --
 * 	public double toUnits(double value){
 * 		return value;
 * 	}
 *
 * 	-- Returns value in other units --
 * 	-- One method for each type in category --
 * 	--Example: UNITS = INCHES, value = 18, Convert toFeet, Return = 1.5 (Feet)
 * 	public double toOtherUnits(double value){
 * 		return value ( / or * ) ####;
 * 	}
 * 		
 * 	-- Converts value value of Unit type sourceUnit into UNITS type --
 * 	-- Example: UNITS = INCHES, value = 1.5, sourceUnit = FEET, return = 18 (Inches)
 * 	public double convert (double value, EnglishUnit sourceUnit){
 * 		return sourceUnit.toUnits(value);
 *	}
 * }
 */
package umuc.cmsc495.mach2.unit.english;

/**
 * @author Michael Swann
 */
public enum EnglishLengthUnit {
    INCHES {
	@Override
	public double toInches(double value) {
	    return value;
	}

	@Override
	public double toFeet(double value) {
	    return value / 12;
	}

	@Override
	public double toYards(double value) {
	    return value / 36;
	}

	@Override
	public double toMiles(double value) {
	    return value / 63360;
	}

	@Override
	public double toMeters(double value) {
	    return value * 0.0254;
	}

	@Override
	public double convert(double value, EnglishLengthUnit sourceUnit) {
	    return sourceUnit.toInches(value);
	}
    },

    FEET {
	@Override
	public double toInches(double value) {
	    return value * 12;
	}

	@Override
	public double toFeet(double value) {
	    return value;
	}

	@Override
	public double toYards(double value) {
	    return value / 3;
	}

	@Override
	public double toMiles(double value) {
	    return value / 5280;
	}

	@Override
	public double toMeters(double value) {
	    return value * 0.3048;
	}

	@Override
	public double convert(double value, EnglishLengthUnit sourceUnit) {
	    return sourceUnit.toFeet(value);
	}
    },

    YARDS {
	@Override
	public double toInches(double value) {
	    return value * 36;
	}

	@Override
	public double toFeet(double value) {
	    return value * 3;
	}

	@Override
	public double toYards(double value) {
	    return value;
	}

	@Override
	public double toMiles(double value) {
	    return value / 1760;
	}

	@Override
	public double toMeters(double value) {
	    return value * 0.9144;
	}

	@Override
	public double convert(double value, EnglishLengthUnit sourceUnit) {
	    return sourceUnit.toYards(value);
	}
    },

    MILES {
	@Override
	public double toInches(double value) {
	    return value * 63360;
	}

	@Override
	public double toFeet(double value) {
	    return value * 5280;
	}

	@Override
	public double toYards(double value) {
	    return value * 1760;
	}

	@Override
	public double toMiles(double value) {
	    return value;
	}

	@Override
	public double toMeters(double value) {
	    return value * 1609.344;
	}

	@Override
	public double convert(double value, EnglishLengthUnit sourceUnit) {
	    return sourceUnit.toMiles(value);
	}
    };

    /**
     * @param sourceValve
     *            Value in Source Units
     * @param sourceUnit
     *            Source Unit Type
     * @return Value in Target Units
     */
    public abstract double toInches(double value);

    public abstract double toFeet(double value);

    public abstract double toYards(double value);

    public abstract double toMiles(double value);

    public abstract double toMeters(double value);

    public abstract double convert(double sourceValve, EnglishLengthUnit sourceUnit);
}
